package com.xinqi.modules.course.curriculum.controller.web;

import com.xinqi.common.base.response.R;
import com.xinqi.common.satoken.utils.LoginHelper;
import com.xinqi.modules.course.curriculum.dto.req.CourseCurriculumCreateDTO;
import com.xinqi.modules.course.curriculum.dto.req.CourseCurriculumUpdateDTO;
import com.xinqi.modules.course.curriculum.dto.rsp.CourseCurriculumResultDTO;
import com.xinqi.modules.course.curriculum.service.CourseCurriculumService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * WEB -- 课程表
 *
 * @version V1.0
 * @Title:
 * @ClassName: com.xinqi.modules.course.curriculum.controller.web.CourseCurriculumWebController.java
 * @Description:
 * @Copyright 星齐科技（云南）有限公司 - Powered By 技术部
 * @author: yyzhen
 * @date: 2023/9/5 10:00
 */
@Tag(name = "Web-课程表", description = "课程表Web接口")
@RestController
@RequestMapping("/web/course-curriculum")
@RequiredArgsConstructor
public class CourseCurriculumWebController {
    private final CourseCurriculumService courseCurriculumService;

    @Operation(summary = "获取当前用户课程表")
    @GetMapping("/list")
    public R<List<CourseCurriculumResultDTO>> listByUser() {
        return R.data(courseCurriculumService.listByUser(LoginHelper.getUserId()));
    }

    @Operation(summary = "课程表-详情")
    @GetMapping("/info/{id}")
    public R<CourseCurriculumResultDTO> findById(@PathVariable("id") Long id) {
        CourseCurriculumResultDTO dto = courseCurriculumService.findById(id);
        return R.data(dto);
    }

    @Operation(summary = "新增课程表")
    @PostMapping("/add")
    public R<Long> insert(@Validated @RequestBody CourseCurriculumCreateDTO dto) {
        return R.data(courseCurriculumService.insert(dto));
    }

    @Operation(summary = "修改课程表")
    @PostMapping("/edit")
    public R<Boolean> update(@Validated @RequestBody CourseCurriculumUpdateDTO dto) {
        return R.data(courseCurriculumService.updateById(dto));
    }

    @Operation(summary = "删除课程表")
    @GetMapping("/remove/{id}")
    public R<Boolean> delete(@PathVariable("id") Long id) {
        return R.data(courseCurriculumService.deleteById(id));
    }

}
